fix: eth_estimateGas failing with not enough funds for L1 fee#3169
fix: eth_estimateGas failing with not enough funds for L1 fee#3169
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes eth_estimateGas failing for low-/zero-balance from addresses by preventing L1 fee charging during the EVM simulation, while still returning an l1_fee estimate computed from the execution’s recorded L1 diff size.
Changes:
- Run
eth_estimateGassimulations withl1_fee_rate = 0to avoid"Not enough funds for L1 fee"failures during inspection. - Recompute
l1_feein the RPC handler usingtx_info.l1_diff_size * real_l1_fee_rate(instead of relying ontx_info.l1_feeproduced by a zero-fee simulation). - Add
test_estimate_gas_no_balanceto cover estimateGas behavior whenfromhas zero balance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/evm/src/query.rs |
Adjusts estimate gas execution to simulate with zero L1 fee rate and recompute L1 fee from l1_diff_size. |
crates/evm/src/tests/queries/estimate_gas_tests.rs |
Adds a regression test ensuring eth_estimateGas succeeds for zero-balance from (except value transfers). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/evm/src/query.rs
Outdated
| let block_gas_limit = U64::from(block_env_gas_limit); | ||
| let block_env_base_fee = U256::from(block_env.basefee); | ||
|
|
||
| let inspect_l1_fee_rate = if account.balance > 0 { |
There was a problem hiding this comment.
Upon discussion with Esad, we decided to run with zero L1 fee only if "from" account balance is zero(this is the case in simulations).
This is to keep the functionality where we can learn that a regular tx will fail due to L1 fee using eth_estimateGas.
| apply_state_overrides(state_overrides.clone(), &mut evm_db)?; | ||
| } | ||
|
|
||
| let account: crate::AccountInfo = evm_db |
There was a problem hiding this comment.
from is Nonce case is covered with address 0x000..00 but in many networks, this address has a balance so the assumption is broken (wrt simulations) so please handle this differently
Description
When the "from" address has a low balance,
eth_estimateGaswas failing because we were inspecting the transaction with non zero L1 fee rate.This PR fixes the issue by executing with a zero L1 fee rate, and then computing the l1 fee in the handler using the l1 diff from execution.
Testing
Added
test_estimate_gas_no_balance.